(function() {
var cj = {
	dropdownMenu: 1,
	axis: 900000,
	param: function (url, param) {
		return url + (!param ? '' : (url.indexOf('?') > -1 ? '&' + param : '?' + param));
	},
	rand: function () {
		return 'rand=' + ~(Math.random() * -1e5)
	},
	int: function (a, b) {//a要设置的，b默认值，当a不是数字并且小于b时按b值
		b = b || 0;
		if (!a) {
			return b;
		}
		a = parseInt(a, 10);
		if (isNaN(a) && a < (!b ? b = 1 : b)) a = b;
		return a;
	},
	toSize: function (a) {
		a = this.int(a);
		if(a == 0) return '0';
		var data = ['B', 'K', 'M', 'G', 'T'], i = 0;
		while(a >= 1024) {
			a /= 1024;
			i++;
		}
		return a.toFixed(2) + data[i];
	}
};
window.cj = cj.prototype = cj;	
})();
$.fn.extend({
	/**
	 * 给文本域或框架按内容自动调整高度
	 * @param a
	 * @returns {*}
	 */
	autoHeight: function(a){
		a = a || 50;
		return this.each(function(){
			var self = $(this);
			self.on('keyup', function(){
				var c = $(this).outerHeight(), d = this.scrollHeight, e = d < a ? a : d, f = d >= c ? d : e;
				self.stop(true,true).animate({height: f}, 300);
			})
			.on('keydown', function(){
				self.stop(true,true);
			});
		});
	},
	/**
	 * 全选/反选
	 * @returns {*}
	 */
    selectAll: function(){
        return $(this).prop('checked', function(i,n){return !n;});
    },
    checkEmpty: function(opts){
		var opt = $.extend({
			parent: '.form-group',
			yes: 'has-success',
			error: 'has-error',
			test: ''
		}, opts || {});
		return this.each(function(){
			var self = $(this), parent = self.parents(opt.parent),
			yes = opt.yes, error = opt.error, test = opt.test;
			self.on('keyup focusout', function(){
				var v = $(this).val();
				if(v == '' || v == '0') {
					parent.addClass(error).removeClass(yes);
				} else if(test != '') {
					if(!(test).test(v)) {
						parent.addClass(error).removeClass(yes);
					} else {
						parent.addClass(yes).removeClass(error);
					}
				} else {
					parent.addClass(yes).removeClass(error);
				}
			});
		});
	},
	getView: function(url){
		if(!url) {
			url = './ajax.asp?q=getViewList';
		}
		var itself = this, cache = {},
		get_data = function() {
			$.json(url, function(a) {
				if(!$.isEmptyObject(a) && a.error == 0) {
					cache = a.message;
					set_data();
				}
			});
		},
		set_data = function() {
			if(!$.isEmptyObject(cache)) {
				itself.each(function(){
					var self = $(this), name = self.attr('data-name'), id = self.attr('data-id'),
					val = ['<select id="'+name+'" name="'+name+'" class="form-control inline w30">',
						'<option value="0">选择模板</option>'];
					$.each(cache, function(i, n) {
						val.push('<option value="' + n[0] + '"' +
							(id == n[0] ? ' selected="selected"' : '') +
							'>' + n[1] + '</option>');
					});
					val.push('</select>');
					self.html(val.join(''));
				});
			}
		};
		get_data();
	},
	/**
	 * 取得大类、栏目、大类下的所有分类
	 * @param opts
	 */
	getKind: function(opts){
		var opt = $.extend({
			url: './ajax.asp?q=getGenreClass',
			type: 'checkbox', //select|checkbox
			data: '', //格外加上的参数
			name: '', //ID和name
			callback: null //ajax取数据后的回调方法，第1个参数为返回的数据
		}, opts || {});
		var itself = this, cache = {}, callback = opt.callback,
		get_data = function() {
			$.json({
				url: opt.url,
				data: opt.data
			}, function(a) {
				if(!$.isEmptyObject(a) && a.error == 0) {
					cache = a.message;
					set_data();
				}
			});
		},
		set_data = function() {
			if(!$.isEmptyObject(cache)) {
				itself.each(function(){
					var self = $(this), name = self.attr('data-name') || opt.name, //genreID|classID
						id = self.attr('data-id'), val = [], cid = {}, checkbox = (opt.type == 'checkbox');
					if(id.indexOf(',') > -1) {
						$.each(id.split(','), function(i, n) {
							cid['c'+n] = n; //加个c在前面，有些浏览器把数字为key的数组重新排序
						});
					} else {
						cid['c'+id] = id;
					}
					if(checkbox) {
						$.each(cache, function(i, n) {
							val.push(['<label class="btn btn-xs btn-default mr10"> ',
								'<input type="checkbox" value="' + n[0] + '" name="'+name+'"',
								(cid['c'+n[0]] ? ' checked="checked"' : ''),
								'> ' + n[2] + '</label>'].join(''));
						});
					} else { //select
						val.push('<select id="'+name+'" name="'+name+'" class="form-control inline w30">');
						$.each(cache, function(i, n) {
							val.push(['<option value="' + n[0] + '"',
								(cid['c'+n[0]] ? ' selected="selected"' : ''),
								'>' + n[2] + '</option>'].join(''));
						});
						val.push('</select>');
					}
					self.html(val.join(''));
				});
				callback && callback.call(itself, cache);
			}
		};
		get_data();
	},
	deleteOne: function (url) {
		return this.each(function () {
			var id = $(this).attr('data-id');
			if(id) {
				$.message({
					c: '删除后不可恢复！确定删除吗？',
					callback: function() {
						$.json(cj.param(url || file + '?q=delete', 'id=' + id), function(a) {
							if(!$.isEmptyObject(a) && a.error == '0') {
								$.message({
									c: '删除成功',
									close: function() {
										location.reload(true);
									}
								});
							}
						});
						return true;
					}
				});
			}
		});
	},
	statusOne: function(url) {
		return this.each(function () {
			var self = $(this), id = self.attr('data-id'), status = self.attr('data-status');
			$.json(cj.param(url || file + '?q=status', 'id=' + id + '&isStop=' + status), function(a) {
				if(!$.isEmptyObject(a) && a.error == '0') {
					$.message({
						c: a.message,
						close: function() {
							location.reload(true);
						}
					});
				}
			});
		});
	},
	statusBatch: function(opts){
		var opt = $.extend({
			url: file + '?q=status',
			data: $('input[name="batchId"]').serialize()
		}, opts || {});
		return this.each(function () {
			var self = $(this), data = opt.data,
				status = self.attr('data-status'),
				name = self.attr('data-name') || 'isStop';
			if(!data || $.isEmptyObject(data)) {
				return $.message({c: '请勾选项目!'});
			}
			$.json({
				url: opt.url,
				data: data + '&' + name + '=' + status
			}, function(a) {
				if(!$.isEmptyObject(a) && a.error == '0') {
					$.message({
						c: a.message,
						close: function() {
							location.reload(true);
						}
					});
				}
			});
		});
	},
	setBool: function (ok, method) {
		var ico = ['<i class="glyphicon glyphicon-remove text-danger"></i>',
			'<i class="glyphicon glyphicon-ok text-success"></i>'];
		return this.each(function () {
			var self = $(this), o = ok ? 1 : 0, v = String(self.attr('data-value').toLowerCase());
			method = !method ? 'html' : method;
			v = (!v || v == 'false' || v == '0') ? 0 : 1;
			if(o == 0) {
				v = !v ? 1 : 0;
			}
			self[method](ico[v]);
		});
	}
});
$.extend($, {
	cookie: function (a, b, c) {
		if (typeof b !== "undefined") {
			c = c || {};
			if (b === null) {b = ''; c.expires = -1;}
			var d = '', e;
			if (c.expires && (typeof c.expires == 'number' || c.expires.toUTCString)) {
				if (typeof c.expires == 'number') {
					e = new Date();
					e.setTime(e.getTime() + (c.expires * 864e5));
				} else e = c.expires;
				d = '; expires=' + e.toUTCString();
			}
			var f = c.path ? '; path=' + (c.path) : '', g = c.domain ? '; domain=' + (c.domain) : '',
				h = c.secure ? '; secure' : '';
			return document.cookie = [a, '=', encodeURIComponent(b), d, f, g, h].join('');
		} else {
			var g = null;
			if (document.cookie && document.cookie != '') {
				var h = document.cookie.split(';');
				for (var i = 0; i < h.length; i++) {
					var j = $.trim(h[i]);
					if (j.substring(0, a.length + 1) == (a + '=')) {
						g = decodeURIComponent(j.substring(a.length + 1));
						break;
					}
				}
			}
			return g;
		}
	},
	json: function(opts, callback, error){
		var opt = {};
		if(typeof(opts) === 'string') {
			opt.url = opts;
		} else {
			opt = opts;
		}
		var u = opt.url, data = opt.data || '', type = opt.type || 'post';
		if(!u) {
			$.message({c:'参数错误！'});
			return this;
		}
		u = cj.param(u, 'ajax=1');
		$.ajax({
			url: cj.param(u, cj.rand()),
			data: data,
			type: type,
			dataType: opt.dataType || 'json',
			error: function(a, b, c){
				$.message({c:'错误代码:' + a.status + ',错误信息:' + c});
				error && error.call(this, a, c);
			},
			success: function(data, success, xhr){
				if(xhr.status == 200) {
					if(data.error != '0') {
						$.message({c: data.message || '未知错误'});
						error && error.call(this, data);
					}
					callback && callback.call(this, data);
				}
			}
		});
		return this;
	},
	message: function(opts) {
		var opt = $.extend({
			c: '', //提示内容
			t: '提示消息', //提示标题
			s: 3, //多少秒自动关闭
			w: 600, //宽度
			callback: null, //确认时回调
			close: null //关闭的回调
		}, opts || {}), callback = opt.callback, close = opt.close, body = $(document.body),
		box = $([
			'<div class="modal fade clewMessage" tabindex="-1" role="dialog" aria-hidden="true">',
			'<div class="modal-dialog"><div class="modal-content">',
			'<div class="modal-header">',// list-group-item active message-header
			'<span class="close" data-dismiss="modal" aria-hidden="true">&times;</span>',
			'<h4 class="modal-title text-center"></h4>',
			'</div><div class="modal-body text-danger">',
			'</div><div class="modal-footer">',
			'<span class="btn btn-default" data-dismiss="modal">关闭</span>',
			callback ? '<span class="btn btn-primary btn-confirm">确定</span>' : '',
			'</div></div></div></div>'
		].join('')).appendTo(body);
		if(opt.w != 600) {
			box.find('.modal-dialog').width(opt.w);
		}
		if(window != top.window) {
			box.find('.modal-dialog').css('margin-top', $(top.window).scrollTop());
		}
		box.find('h4').html(opt.t);
		box.find('.modal-body').html(opt.c);
		box.modal().on('hidden.bs.modal', function () {
			box.remove();
			var length = $('.clewMessage').length;
			if(length == 0) {
				body.css('padding-right', 0).removeClass('modal-open');
				delete($.CLEW_MESSAGE);
			} else if(length > 0) {
				body.css('padding-right', $.CLEW_MESSAGE).addClass('modal-open');
			}
			close && close.call(box);
		});
		if(callback) {
			box.find('.btn-confirm').on('click', function(){
				if(callback.call(box)) {
					box.modal('hide');
				}
			});
		} else if(!callback && opt.s > 0) {
			setTimeout(function(){
				box.modal('hide');
			}, opt.s * 1000);
		}
		if(!$.CLEW_MESSAGE) {
			$.CLEW_MESSAGE = body.css('padding-right');
		}
		return box;
	},
	/**
	 * JS分页
	 * @param opts object
	 * @returns {*}
	 */
	page: function(opts) {
		var opt = $.extend({
			fn: '', //链接
			total: 0, //总数量
			page: 1, //当前页
			rows: 20, //每页数
			down: 'up' //down|up
		}, opts || {}),
		fn = opt.fn, down = opt.down == 'up' ? 'dropup' : 'dropdown',
		page = cj.int(opt.page),
		rows = cj.int(opt.rows, 20),
		total = cj.int(opt.total, 0);
		if(!page || !rows || !total) {
			return '';
		}
		//[10, 20, 30, 40, 50, 100, 200, 500, 1000] 下拉的数组
		var i = 1, pageSize = [1000, 500, 200, 100, 50, 40, 30, 20, 10], htm = [],
		totalPage = Math.ceil(total / rows);//totalPage 总页数
		if (page > totalPage) {
			page = totalPage;
		}
		htm.push('<li><span>' + total + '条,' + totalPage + '页</span></li>');
		if (total > rows) {
			if (page > 1) {
				htm.push('<li><a href="' + cj.param(fn, 'page=1&rows=' + rows) + '" title="第1页">&lt;&lt;</a></li>');
				htm.push('<li><a href="' + cj.param(fn, 'page=' + (page - 1) + '&rows=' + rows) + '" title="第' + (page - 1) + '页">&lt;</a></li>');
			}
			if ((page - 4) <= 0 || totalPage < 10) {
				for (i = 1; i < 10; i++) {
					htm.push(i == page ?
						'<li class="active"><span>' + i + '</span></li>' :
						'<li><a href="' + cj.param(fn, 'page=' + i + '&rows=' + rows) + '" title="第' + i + '页">' + i + '</a></li>');
					if (i == totalPage) break;
				}
			} else if ((page + 4) >= totalPage) {
				for (i = totalPage - 8; i <= totalPage; i++) {
					htm.push(i == page ?
						'<li class="active"><span>' + i + '</span></li>' :
						'<li><a href="' + cj.param(fn, 'page=' + i + '&rows=' + rows) + '" title="第' + i + '页">' + i + '</a></li>');
				}
			} else {
				for (i = page - 4; i < page + 5; i++) {
					htm.push(i == page ?
						'<li class="active"><span>' + i + '</span></li>' :
						'<li><a href="' + cj.param(fn, 'page=' + i + '&rows=' + rows) + '" title="第' + i + '页">' + i + '</a></li>');
				}
			}
			if (page < totalPage) {
				htm.push('<li><a href="' + cj.param(fn, 'page=' + (page + 1) + '&rows=' + rows) + '" title="第' + (page + 1) + '页">&gt;</a></li>');
				htm.push('<li><a href="' + cj.param(fn, 'page=' + totalPage + '&rows=' + rows) + '" title="最后第' + totalPage + '页">&gt;&gt;</a></li>');
			}
		}
		htm.push('<li><span class="' + down + '">');
		htm.push('<span data-toggle="dropdown" class="dropdown-toggle" href="javascript:;">');
		htm.push(rows + '条/页<span class="caret"></span></span>');
		htm.push('<ul class="dropdown-menu">');
		$.each(pageSize, function(k, v){
			htm.push('<li><a href="' + cj.param(fn, 'page=' + page + '&rows=' + v) + '"');
			htm.push((v == rows ? ' class="btn-default"' : '')+'>' + v + '</a></li>');
		});
		htm.push('</ul></span></li>');

		htm = '<ul class="pagination">' + htm.join('') + '</ul>';
		return htm;
	},
	deleteBatch: function(opts){
		var opt = $.extend({
			url: file + '?q=delete',
			t: '提示信息',
			msg: '删除后不可恢复！确定删除？',
			data: $('input[name="batchId"]').serialize()
		}, opts || {}), url = opt.url, data = opt.data;
		if(!data || $.isEmptyObject(data)) {
			return $.message({c: '请勾选项目!'});
		}
		$.message({
			t: opt.t,
			c: opt.msg,
			callback: function() {
				$.json({
					url: url,
					data: data
				}, function(a) {
					if(!$.isEmptyObject(a) && a.error == '0') {
						$.message({
							c: a.message,
							close: function() {
								location.reload(true);
							}
						});
					}
				});
				return true;
			}
		});
	},
	editBatch: function(opts){
		var opt = $.extend({
			url: file + '?q=editBatch',
			data: $('input[name="batchId"]').serialize()
		}, opts || {}), data = opt.data;
		if(!data || $.isEmptyObject(data)) {
			return $.message({c: '请勾选要修改的ID'});
		}
		location.href = cj.param(opt.url, data);
	},
	submitForm: function (ele) {
		var check = true, msg = [];
		$(ele).each(function() {
			var self = $(this), val = self.val(), group = self.parents('.form-group');
			if(val == '') {
				check = false;
				msg.push(self.attr('placeholder'));
				group.addClass('has-error').removeClass('has-success');
			} else {
				group.addClass('has-success').removeClass('has-error');
			}
		});
		if(!check) {
			$.message({c: '必填项: ' + msg.join(', ') + ' 不可以为空！'});
		}
		return check;
	}
});
$(document).ready(function() {
	$('.submit_box').html([
		'<span class="btn btn-default w10 mr10 back_page">返回</span>',
		'<button type="submit" class="btn btn-primary w30 mr10">确定</button>',
		'<button type="reset" class="btn btn-default w10 mr10">重置</button>',
		'<span class="btn btn-default w10 reload">刷新</span>'
	].join(''));
	//$('textarea').autoHeight();
	$('textarea').each(function(){
		$(this).height(this.scrollHeight);
	});
	$('.clean').attr('title', '双击清除内容');
$(this)
	//返回
	.on('click', '.back_page', function() {
		history.back();
	})
	//点击图片看大图
	.on('click', '.show_pic', function() {
		$.message({
			t: '查看大图',
			c: '<div class="text-center"><img src="'+ $(this).attr('src') + '" class="img-thumbnail" /></div>',
			s: 0,
			w: $(window).width()*0.8
		});
	})
	//绑定刷新
	.on('click', '.reload', function() {
		location.reload(true);
	})
	//搬到全选、反选
	.on('click', '.selectAll', function() {
		$('input[name="batchId"]').selectAll();
	})
	//双击清除内容
	.on('dblclick', '.clean', function() {
		this.value = '';
	})
});
/* =========================================================
 * 日历插件(修改过,与原版不一样) bootstrap-datePicker.js
 * http://www.eyecon.ro/bootstrap-datepicker
 * =========================================================
 * Copyright 2012 Stefan Petre
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ========================================================= */
!function($){var j=function(a,b){this.element=$(a);this.format=k.parseFormat(b.format||this.element.data('date-format')||'yyyy-mm-dd');this.picker=$(k.view).appendTo('body').on({click:$.proxy(this.click,this)});this.isInput=this.element.is('input');this.component=this.element.is('.date')?this.element.find('.add-on'):false;if(this.isInput){this.element.on({focus:$.proxy(this.show,this),keyup:$.proxy(this.update,this)})}else{if(this.component){this.component.on('click',$.proxy(this.show,this))}else{this.element.on('click',$.proxy(this.show,this))}}this.minViewMode=b.minViewMode||this.element.data('date-minviewmode')||0;if(typeof this.minViewMode==='string'){switch(this.minViewMode){case'months':this.minViewMode=1;break;case'years':this.minViewMode=2;break;default:this.minViewMode=0;break}}this.viewMode=b.viewMode||this.element.data('date-viewmode')||0;if(typeof this.viewMode==='string'){switch(this.viewMode){case'months':this.viewMode=1;break;case'years':this.viewMode=2;break;default:this.viewMode=0;break}}this.startViewMode=this.viewMode;this.weekStart=b.weekStart||this.element.data('date-weekstart')||0;this.weekEnd=this.weekStart===0?6:this.weekStart-1;this.onRender=b.onRender;this.fillDow();this.fillMonths();this.update();this.showMode()};j.prototype={constructor:j,show:function(e){this.picker.show();this.height=this.component?this.component.outerHeight():this.element.outerHeight();this.place();$(window).on('resize',$.proxy(this.place,this));if(e){e.stopPropagation();e.preventDefault()}if(!this.isInput){}var b=this;$(document).on('mousedown',function(a){if($(a.target).closest('.datePicker').length==0){b.hide()}});this.element.trigger({type:'show',date:this.date})},hide:function(){this.picker.hide();$(window).off('resize',this.place);this.viewMode=this.startViewMode;this.showMode();if(!this.isInput){$(document).off('mousedown',this.hide)}this.element.trigger({type:'hide',date:this.date})},set:function(){var a=k.formatDate(this.date,this.format),date=!this.isInput&&this.component?this.element.find('input').val():this.element.val();if(date==''){date=a}else{date=date.replace(/\d{4}-\d{1,2}-\d{1,2}/,a)}if(!this.isInput){if(this.component){this.element.find('input').prop('value',date)}this.element.data('date',date)}else{this.element.prop('value',date)}},setValue:function(a){if(typeof a==='string'){this.date=k.parseDate(a,this.format)}else{this.date=new Date(a)}this.set();this.viewDate=new Date(this.date.getFullYear(),this.date.getMonth(),1,0,0,0,0);this.fill()},place:function(){var a=this.component?this.component.offset():this.element.offset();this.picker.css({top:a.top+this.height,left:a.left})},update:function(a){this.date=k.parseDate(typeof a==='string'?a:(this.isInput?this.element.prop('value'):this.element.data('date')),this.format);this.viewDate=new Date(this.date.getFullYear(),this.date.getMonth(),1,0,0,0,0);this.fill()},fillDow:function(){var a=this.weekStart,html=['<tr>'];while(a<this.weekStart+7){html.push('<th class="dow">'+k.dates.daysMin[(a++)%7]+'</th>')}html.push('</tr>');this.picker.find('.datePicker-days thead').append(html.join(''))},fillMonths:function(){var a=[],i=0;while(i<12){a.push('<span class="month">'+k.dates.monthsShort[i++]+'</span>')}this.picker.find('.datePicker-months td').append(a.join(''))},fill:function(){var d=new Date(this.viewDate),year=d.getFullYear(),month=d.getMonth(),currentDate=this.date.valueOf();this.picker.find('.datePicker-days .switched').text(year+'年'+k.dates.months[month]);var a=new Date(year,month-1,28,0,0,0,0),day=k.getDaysInMonth(a.getFullYear(),a.getMonth());a.setDate(day);a.setDate(day-(a.getDay()-this.weekStart+7)%7);var b=new Date(a);b.setDate(b.getDate()+42);b=b.valueOf();var c=[];var e,prevY,prevM;while(a.valueOf()<b){if(a.getDay()===this.weekStart){c.push('<tr>')}e=this.onRender(a);prevY=a.getFullYear();prevM=a.getMonth();if((prevM<month&&prevY===year)||prevY<year){e+=' old'}else if((prevM>month&&prevY===year)||prevY>year){e+=' new'}if(a.valueOf()===currentDate){e+=' active'}c.push('<td class="day '+e+'">'+a.getDate()+'</td>');if(a.getDay()===this.weekEnd){c.push('</tr>')}a.setDate(a.getDate()+1)}this.picker.find('.datePicker-days tbody').empty().append(c.join(''));var f=this.date.getFullYear();var g=this.picker.find('.datePicker-months').find('th:eq(1)').text(year).end().find('span').removeClass('active');if(f===year){g.eq(this.date.getMonth()).addClass('active')}c='';year=parseInt(year/10,10)*10;var h=this.picker.find('.datePicker-years').find('th:eq(1)').text(year+'-'+(year+9)).end().find('td');year-=1;for(var i=-1;i<11;i++){c+='<span class="year'+(i===-1||i===10?' old':'')+(f===year?' active':'')+'">'+year+'</span>';year+=1}h.html(c)},click:function(e){e.stopPropagation();e.preventDefault();var a=$(e.target).closest('span, td, th'),month,year,day;if(a.length===1){switch(a[0].nodeName.toLowerCase()){case'th':switch(a[0].className){case'switched':this.showMode(1);break;case'prev':case'next':this.viewDate['set'+k.modes[this.viewMode].navFnc].call(this.viewDate,this.viewDate['get'+k.modes[this.viewMode].navFnc].call(this.viewDate)+k.modes[this.viewMode].navStep*(a[0].className==='prev'?-1:1));this.fill();this.set();break}break;case'span':if(a.is('.month')){month=a.parent().find('span').index(a);this.viewDate.setMonth(month)}else{year=parseInt(a.text(),10)||0;this.viewDate.setFullYear(year)}if(this.viewMode!==0){this.date=new Date(this.viewDate);this.element.trigger({type:'changeDate',date:this.date,viewMode:k.modes[this.viewMode].clsName})}this.showMode(-1);this.fill();this.set();break;case'td':if(a.is('.day')&&!a.is('.disabled')){day=parseInt(a.text(),10)||1;month=this.viewDate.getMonth();if(a.is('.old')){month-=1}else if(a.is('.new')){month+=1}year=this.viewDate.getFullYear();this.date=new Date(year,month,day,0,0,0,0);this.viewDate=new Date(year,month,Math.min(28,day),0,0,0,0);this.fill();this.set();this.element.trigger({type:'changeDate',date:this.date,viewMode:k.modes[this.viewMode].clsName})}break}}},mousedown:function(e){e.stopPropagation();e.preventDefault()},showMode:function(a){if(a){this.viewMode=Math.max(this.minViewMode,Math.min(2,this.viewMode+a))}this.picker.find('>div').hide().filter('.datePicker-'+k.modes[this.viewMode].clsName).show()}};$.fn.datePicker=function(b,c){return this.each(function(){var a=$(this),data=a.data('datePicker'),options=typeof b==='object'&&b;if(!a[0]){return}if(!data){a.data('datePicker',(data=new j(this,$.extend({},$.fn.datePicker.defaults,options))))}if(typeof b==='string')data[b](c)})};$.fn.datePicker.defaults={onRender:function(a){return''}};$.fn.datePicker.Constructor=j;var k={modes:[{clsName:'days',navFnc:'Month',navStep:1},{clsName:'months',navFnc:'FullYear',navStep:1},{clsName:'years',navFnc:'FullYear',navStep:10}],dates:{days:['星期日','星期一','星期二','星期三','星期四','星期五','星期六','星期日'],daysShort:['日','一','二','三','四','五','六','日'],daysMin:['日','一','二','三','四','五','六','日'],months:['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],monthsShort:['1','2','3','4','5','6','7','8','9','10','11','12']},isLeapYear:function(a){return(((a%4===0)&&(a%100!==0))||(a%400===0))},getDaysInMonth:function(a,b){return[31,(k.isLeapYear(a)?29:28),31,30,31,30,31,31,30,31,30,31][b]},parseFormat:function(a){var b=a.match(/[.\/\-\s].*?/),parts=a.split(/\W+/);if(!b||!parts||parts.length===0){throw new Error("Invalid date format.");}return{separator:b,parts:parts}},parseDate:function(a,b){var c=a.split(b.separator),date=new Date(),val;date.setHours(0);date.setMinutes(0);date.setSeconds(0);date.setMilliseconds(0);if(c.length===b.parts.length){var d=date.getFullYear(),day=date.getDate(),month=date.getMonth();for(var i=0,cnt=b.parts.length;i<cnt;i++){val=parseInt(c[i],10)||1;switch(b.parts[i]){case'dd':case'd':day=val;date.setDate(val);break;case'mm':case'm':month=val-1;date.setMonth(val-1);break;case'yy':d=2000+val;date.setFullYear(2000+val);break;case'yyyy':d=val;date.setFullYear(val);break}}date=new Date(d,month,day,0,0,0)}return date},formatDate:function(a,b){var c={d:a.getDate(),m:a.getMonth()+1,yy:a.getFullYear().toString().substring(2),yyyy:a.getFullYear()};c.dd=(c.d<10?'0':'')+c.d;c.mm=(c.m<10?'0':'')+c.m;var d=[];for(var i=0,cnt=b.parts.length;i<cnt;i++){d.push(c[b.parts[i]])}return d.join(b.separator)},headView:'<thead><tr><th class="prev">&lsaquo;</th><th colspan="5" class="switched"></th><th class="next">&rsaquo;</th></tr></thead>',contView:'<tbody><tr><td colspan="7"></td></tr></tbody>'};k.view=['<div class="datePicker dropdown-menu"><div class="datePicker-days"><table class="table-condensed">',k.headView,'<tbody></tbody></table></div><div class="datePicker-months"><table class="table-condensed">',k.headView,k.contView,'</table></div><div class="datePicker-years"><table class="table-condensed">',k.headView,k.contView,'</table></div></div>'].join('')}(window.jQuery);

